<template>
  <div class="home">
    <div class="list clearfix">
      <div
        v-for="(item, index) in tabelList"
        :key="item.id"
        class="list-item"
        :class="[
          {
            'list-item-last': index % 3 === 0,
          },
        ]"
        @click="onCLickDetail(item)"
      >
        <el-card class="card" :body-style="{ padding: '0px' }">
          <div class="title text-xl font-bold">{{ item.title }}</div>
          <div class="introduce text-sm">{{ item.introduce }}</div>
          <time class="time">{{ item.update_time }}</time>
        </el-card>
      </div>
    </div>

    <div class="pagination">
      <Pagination
        :page-sizes="paginationConfig.pageSizes"
        :layout="paginationConfig.layout"
        :total="paginationConfig.total"
        :page="paginationConfig.page"
        :limit="paginationConfig.pageSize"
        @pagination="handleChangePage"
      />
    </div>
  </div>
</template>

<script>
import { getCategoryList } from 'api/category'
import { getKnowledgeList } from 'api/knowledge'
import { getCourseList } from 'api/course'
import { getQuestionnaireList } from 'api/questionnaire'
export default {
  name: 'Home',
  data() {
    return {
      tabelList: [],
      paginationConfig: {
        direction: 'center', // 分页位置
        layout: 'total, sizes, prev, pager, next, jumper', // 分页类型
        pageSizes: [10, 20], // 分页pages
        total: 0,
        page: 1, // 页数-默认1
        pageSize: 12 // 每页条数-默认10
      }
    }
  },
  computed: {},
  created() {
    this.getList()
  },
  methods: {
    async getList() {
      const { page, pageSize } = this.paginationConfig
      getQuestionnaireList({
        state: 1,
        page,
        pageSize
      })
        .then((res) => {
          if (res.code === 200) {
            this.tabelList = res.data.list
            this.paginationConfig.total = res.data.total
          }
        })
        .catch((err) => {
          console.log(err)
        })
    },
    handleChangePage({ page, pageSize }) {
      this.paginationConfig.page = page
      this.paginationConfig.pageSize = pageSize
      this.$nextTick(() => {
        this.getList()
      })
    },
    onCLickDetail(item) {
      this.$router.push({
        path: '/questionnaire/detail',
        query: {
          id: item.id
        }
      })
    }
  }
}
</script>
<style lang="scss" scoped>
.home {
  background-color: #f7f7f7;
}
.list {
  width: 1000px;
  margin: 0 auto;
  margin-top: 20px;
  display: flex;
  flex-direction: row;
  justify-content: flex-start;
  min-height: 65vh;
  //background-color: #fff;
  .list-item {
    width: 33%;
    margin-bottom: 20px;
    margin-right: 1%;
    padding: 10px 20px;
    &-last {
      margin-right: 0;
    }
  }
  .card {
    padding: 10px 20px;
    height: 13rem;
  }
  .title {
    height: 2.2rem;
  }
  .introduce {
    color: #808080;
    min-height: 8rem;
    max-height: 8rem;
  }
  .time {
    font-size: 13px;
    color: #999;
  }

  .bottom {
    margin-top: 13px;
    line-height: 12px;
  }

  .button {
    padding: 0;
    float: right;
  }

  .image {
    width: 90%;
    border-radius: 20px;
    height: 220px;
    display: block;
    margin: 0 auto;
    margin-top: 10px;
    object-fit: contain;
  }
}
.pagination {
  margin-top: 20px;
}
.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}

.clearfix:after {
  clear: both;
}
</style>
